// pages/text.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
   islogin:'2',
   loginbtnstate:'true',
   registeripone:'',
   registerpassword:'',
   comebackpassword:'',
   strloginUser:'',
   strloginpassword:'',
   switchChecked:''
  },

  bindswitchchange:function(e){
    console.log(e)
    var that=this
    var m=e.detail.value
    if(m==true){
      that.setData({
        switchChecked:m,
      })
    }
    else if (m==false){
      that.setData({
        switchChecked:m,
      })
    }
    console.log(that.data.switchChecked+'状态')
  },
  



compass:function(e){
  console.log(e.detail.value)
  var that=this
  var m=e.detail.value
  if(m!=''&&(m.length==11)){
    that.setData({
      comebackpassword:m,
      loginbtnstate:false
      
    })
  }
    else
    {
      that.setData({
        loginbtnstate:true
      })
    }
  },
  
  
 comebackpassword:function(e){
var that=this
var value = wx.getStorageSync('userjob2')
if(that.data.comebackpassword==value.iphone)
{
  wx.setClipboardData({
    data:value.password,
    success(res){
      wx.getClipboardData({
        success(res){
          console.log(res.data+"密码")
          that.setData({
            islogin:1
          })
          wx.showToast({
            title: '密码已复制',
            duration:2000
          })
        }
      })
    }
      })
 }
      else{
      wx.showToast({
        title: '手机号未注册',
     })
      }
 },




  inputiphone1:function(e){
  console.log(e.detail.value)
  var that=this
  var m=e.detail.value
  if(m!=''&&(m.length==11)){
    that.setData({
      strloginUser:m
    })
    if(that.data.strloginpassword!=''){
      that.setData({
        loginbtnstate:false
      })
    }
    else
    {
      that.setData({
        loginbtnstate:true
      })
    }
  }
  else{
    that.setData({
      loginbtnstate:true
  })
    }
  },

  password2:function(e){
console.log(e.detail.value)
var that=this
var m=e.detail.value
if(m!=''){
  that.setData({
    strloginpassword:m 
  })
  if(that.data.strloginUser!=''&&(that.data.strloginUser.length==11)){
    that.setData({
      loginbtnstate:false
    })
  }
  else{
    that.setData({
      loginbtnstate:true
    })
  }
}
else{
  that.setData({
    loginbtnstate:true
  })
}
  },

  onlogin:function(e){
    var that=this
    if(that.data.switchChecked==true){
      wx.setStorageSync('iphone1', that.data.strloginUser);
      wx.setStorageSync('password1', that.data.strloginpassword);
      wx.setStorageSync('checkedvalue1', that.data.switchChecked);
      wx.setStorageSync('wxlogin1', false);

    }
    else if(that.data.switchChecked==false){
      wx.setStorageSync('iphone1', );
      wx.setStorageSync('password1', );
      wx.setStorageSync('checkedvalue1', false);
      wx.setStorageSync('wxlogin1', true);
    }
    var m=wx.getStorageSync('userjob2')
    if(that.data.strloginUser==m.iphone){
        if(that.data.strloginpassword==m.password){
           wx.showToast({
             title: '登录成功',
           })
           wx.switchTab({
             url: '../index/index',
           })
        }
        else{
          wx.showToast({
            title: '密码错误',
          })
        }
    }
    else{
      wx.showToast({
        title: '手机号未注册',
      })
    }
  },


  formsubmit:function(e){
  console.log(e)
  var obj={}
  obj.iphone=e.detail.value.registeriphone
  obj.password=e.detail.value.registerpassword
  wx.setStorageSync('userjob2', 'value',obj)
  wx.showToast({
    title: '注册成功',
  })
  this.setData({
    islogin:1
  })
},



  register:function(e){
    this.setData({
      islogin:3
    })
  },
   denglu:function(e){
    this.setData({
      islogin:1
    })
  },
  forget:function(e){
    this.setData({
      islogin:2
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:function(options) {
    var that=this
    that.setData({
      strloginUser:wx.getStorageSync('iphone1'),
      strloginpassword:wx.getStorageSync('password1'),
      switchChecked:wx.getStorageSync('checkedValue1'),
      loginbtnstate:wx.getStorageSync('wxlogin1'),
 })
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})